<?php
$idcid = $conf['defaultcid'] == '' ? '1' : $conf['defaultcid'];
$shop_cid = $_GET['shop_cid'] == '' ? $idcid : $_GET['shop_cid'];
if ($islogin2 == 1) {
  $price_obj = new \lib\Price($userrow['zid'], $userrow);
} elseif ($is_fenzhan == true) {
  $price_obj = new \lib\Price($siterow['zid'], $siterow);
} else {
  $price_obj = new \lib\Price(1);
}
$classhide = explode(',', $siterow['class']);
$rs = $DB->query("SELECT * FROM pre_class WHERE active=1 order by sort asc");
$shua_class = array();
while ($res = $rs->fetch()) {
  if ($is_fenzhan && in_array($res['cid'], $classhide)) continue;
  $shua_class[$res['cid']] = $res['name'];
}

// 初始化变量
$selectedTid = isset($_GET['tid']) ? intval($_GET['tid']) : null;
$selectedCid = isset($_GET['cid']) ? intval($_GET['cid']) : null;

// 获取商品信息
$total = null;
$info_desc = "请选择您需要的商品";
$num_val = 1;

if ($selectedTid && $selectedCid) {
    $rs2 = $DB->query("SELECT * FROM pre_tools WHERE tid='$selectedTid' AND cid='$selectedCid' AND active=1 LIMIT 1");
    if ($res = $rs2->fetch()) {
        if (isset($price_obj)) {
            $price_obj->setToolInfo($res['tid'], $res);
            if ($price_obj->getToolDel($res['tid']) != 1) {
                $price = $price_obj->getToolPrice($res['tid']);
                $total = $price * $num_val;
                $info_desc = htmlspecialchars($res['desc'], ENT_QUOTES, 'UTF-8');
            }
        } else {
            $price = $res['price'];
            $total = $price * $num_val;
            $info_desc = htmlspecialchars($res['desc'], ENT_QUOTES, 'UTF-8');
        }

        if ($res['is_curl'] == 4) {
            $count = $DB->getColumn("SELECT count(*) FROM pre_faka WHERE tid='{$res['tid']}' and orderid=0");
            if ($count > 0 && $conf['faka_showleft'] == 0) $status = '' . $count . '个';
            elseif ($count > 0) $status = '充足';
            else $status = '缺货';
        } elseif ($res['stock'] !== null) {
            $count = $res['stock'];
            if ($count > 0 && $conf['faka_showleft'] == 0) $status = '库存' . $count . '张</font>';
            elseif ($count > 0) $status = '充足';
            else $status = '缺货';
        } else {
            if ($res['close'] == 1) $status = '已下架';
            else $status = '正常';
        }
    }
}
?>

<div id="app">
    <section class="category">
        <div class="category_title d-flex align-content-center">
            <span>选择分类</span>
        </div>
        <div class="category_list">
            <?php foreach($shua_class as $cid => $classname): ?>
                <div onclick="window.location.href = './?shop_cid=<?php echo htmlspecialchars($cid, ENT_QUOTES, 'UTF-8') ?>'" class="category_box" data-cateid="<?php echo htmlspecialchars($cid, ENT_QUOTES, 'UTF-8') ?>">
                    <img src="./assets/yunjii/cid.png">
                    <div class="cate_name"><?php echo htmlspecialchars($classname, ENT_QUOTES, 'UTF-8') ?></div>
                    <div class="cate_desc">自动发货</div>
                </div>
            <?php endforeach; ?>
        </div>
    </section>

    <section class="goods">
        <div class="goods_title d-flex align-content-center">
            <span>选择商品</span>
        </div>
        <div class="goods_list" style="max-height: 380px; overflow-x: auto;">
            <?php
            $idcid = $conf['indexClass_ID'] == '' ? '1' : $conf['indexClass_ID'];
            $shop_cid = $_GET['shop_cid'] == '' ? $idcid : $_GET['shop_cid'];
            $rs2 = $DB->query("SELECT * FROM pre_tools WHERE cid='$shop_cid' and active=1 order by sort asc");
            while ($res = $rs2->fetch()) {
                if (isset($price_obj)) {
                    $price_obj->setToolInfo($res['tid'], $res);
                    if ($price_obj->getToolDel($res['tid']) == 1) continue;
                    $price = $price_obj->getToolPrice($res['tid']);
                } else $price = $res['price'];

                if ($res['is_curl'] == 4) {
                    $count = $DB->getColumn("SELECT count(*) FROM pre_faka WHERE tid='{$res['tid']}' and orderid=0");
                    if ($count > 0 && $conf['faka_showleft'] == 0) $status = '' . $count . '个';
                    elseif ($count > 0) $status = '充足';
                    else $status = '缺货';
                } elseif ($res['stock'] !== null) {
                    $count = $res['stock'];
                    if ($count > 0 && $conf['faka_showleft'] == 0) $status = '库存' . $count . '张</font>';
                    elseif ($count > 0) $status = '充足';
                    else $status = '缺货';
                } else {
                    if ($res['close'] == 1) $status = '已下架';
                    else $status = '正常';
                }

                if ($res['is_curl'] == 1 || $res['is_curl'] == 2 || $res['is_curl'] == 4 || $res['is_curl'] == 5) {
                    $isauto = true;
                } else {
                    $isauto = false;
                }
                echo '
                <div onclick="selectGoods(' . htmlspecialchars($res['tid'], ENT_QUOTES, 'UTF-8') . ', ' . htmlspecialchars($shop_cid, ENT_QUOTES, 'UTF-8') . ')" class="goods_box" data-goods_id="' . htmlspecialchars($res['tid'], ENT_QUOTES, 'UTF-8') . '">
                    <img src="./assets/yunjii/img/maibianjiao.png" class="icon"/>
                    <div></div>
                    <div class="goods_name">' . htmlspecialchars($res['name'], ENT_QUOTES, 'UTF-8') . '</div>
                    <div class="goods_price">￥' . htmlspecialchars($price, ENT_QUOTES, 'UTF-8') . '</div>
                    <div class="goods_remark" style="color: #0db26a; background: #e1fff2"><span>' . htmlspecialchars($status, ENT_QUOTES, 'UTF-8') . '</span></div>
                </div>
                ';
            }
            ?>
        </div>
    </section>

    <section class="desc">
        <div class="sale_message" id="isdiscount_span" style="display: none;">
            <svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
                <path d="M988.908308 614.006154c-58.525538-29.538462-76.091077-53.208615-76.091077-100.509539 0-44.386462 17.565538-68.017231 76.091077-100.548923 32.177231-20.716308 35.091692-38.439385 35.091692-68.01723v-168.566154C1024 123.116308 980.125538 78.769231 927.468308 78.769231H96.492308C43.874462 78.769231 0 123.116308 0 176.364308v168.566154c0 26.584615 2.914462 50.254769 35.091692 68.01723 23.433846 11.815385 76.091077 41.353846 76.091077 100.548923 0 65.024-38.045538 85.740308-73.137231 97.555693H35.052308C2.914462 631.768615 0 664.300308 0 679.069538v168.566154C0 900.883692 43.874462 945.230769 96.531692 945.230769H927.507692C980.125538 945.230769 1024 900.883692 1024 847.635692v-168.566154c0-32.531692-11.697231-44.347077-35.091692-65.063384z" fill="#7FBCFF" p-id="61311"></path>
                <path d="M670.444308 530.116923c17.723077 0 32.571077 14.572308 32.571077 32.019692a32.571077 32.571077 0 0 1-32.571077 31.980308h-124.376616v122.171077a32.571077 32.571077 0 0 1-65.142154 0v-122.171077H356.548923a32.571077 32.571077 0 0 1-32.571077-31.980308c0-17.447385 14.808615-32.019692 32.571077-32.019692h124.376615v-75.618461H347.648A32.571077 32.571077 0 0 1 315.076923 422.478769c0-17.447385 14.808615-31.980308 32.571077-31.980307h97.713231L341.740308 288.689231a31.232 31.232 0 0 1 0-43.638154 32.610462 32.610462 0 0 1 44.425846 0l127.330461 125.085538 127.330462-125.085538a32.610462 32.610462 0 0 1 44.386461 0c11.854769 11.618462 11.854769 31.980308 0 43.638154l-103.620923 101.809231h94.759385c17.762462 0 32.571077 14.572308 32.571077 31.980307a32.571077 32.571077 0 0 1-32.571077 32.019693h-133.277538v75.618461h127.369846z" fill="#007AFF" p-id="61312"></path>
            </svg>
            <div class="content sale_message">
                <span></span>
            </div>
        </div>
        <div class="desc_content">
            <svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
                <path d="M392.7 958.9c22.5 0 40.7-18.2 40.7-40.7V630.9c0-22.5-18.2-40.7-40.7-40.7H105.4c-22.5 0-40.7 18.2-40.7 40.7v287.4c0 22.5 18.2 40.7 40.7 40.7h287.3zM860 958.9c22.5 0 40.7-18.2 40.7-40.7V630.9c0-22.5-18.2-40.7-40.7-40.7H572.7c-22.5 0-40.7 18.2-40.7 40.7v287.4c0 22.5 18.2 40.7 40.7 40.7H860zM392.7 492c22.5 0 40.7-18.2 40.7-40.7V164c0-22.5-18.2-40.7-40.7-40.7H105.4c-22.5 0-40.7 18.2-40.7 40.7v287.4c0 22.5 18.2 40.7 40.7 40.7h287.3z" fill="#1E94EE" p-id="42427"></path>
                <path d="M948.3 336.4c15.9-15.9 15.9-41.6 0-57.5L745.1 75.7c-15.9-15.9-41.6-15.9-57.5 0L484.4 278.9c-15.9 15.9-15.9 41.6 0 57.5l203.2 203.2c15.9 15.9 41.6 15.9 57.5 0l203.2-203.2z" fill="#B4DCF5" p-id="42428"></path>
            </svg>
            <div class="content" id="remark" style="word-break: break-all;"><?php echo $info_desc; ?></div>
        </div>
    </section>

    <section class="order_info">
        <div class="info_box">
            <div class="info_left">
                <span>*</span>
                <span>购买数量</span>
            </div>
            <div class="count_right">
                <span onclick="changeQuantity(-1)" style="cursor:pointer"><p>-</p></span>
                <input id="num" type="text" value="<?php echo htmlspecialchars($num_val, ENT_QUOTES, 'UTF-8'); ?>" name="quantity" title="本商品最少购买数量为1件！">
                <span onclick="changeQuantity(1)" style="cursor:pointer"><p>+</p></span>
            </div>
        </div>

        <div class="info_box">
            <div class="info_left">
                <span>*</span>
                <span>联系方式:(填写QQ会自动通知邮箱)</span>
            </div>
        </div>

        <div class="info_box">
            <div class="input_right opt">
                <input id="inputvalue" name="contact" class="phone_num" type="text" placeholder="[必填]推荐QQ或者手机号或下单凭证" required=""
                       style="float: left !important; padding: 10px; margin-left: 10px; border: 1px solid; border-radius: 5px;">
            </div>
            <div class="info_box_msg">
                联系方式特别重要,可用来查询订单
            </div>
        </div>
    </section>

    <section class="xh_box" style="display:none">
        <div style="color: #545454;margin-bottom: .2rem;font-size: .373333rem;font-weight: 700;">
            已选号码<a style="font-size: 12px;float: right;border: 1px solid rgb(204, 0, 0);border-radius: 5px;padding: 2px 6px;color: rgb(204, 0, 0);" href="javascript:void(0)" onclick="selectForm()">重新选择</a>
        </div>
        <div class="xh_box_content"><p style="color: #74788d;padding:10px">未指定号码，系统将随机发货！</p></div>
    </section>

    <div class="border"></div>

    <section class="pay">
        <div class="pay_title">
            支付方式
        </div>
        <div class="pay_list">
            <div style="cursor:pointer" class="pay_box active" data-pid="2" data-rate="0.04">
                <div>
                    <span>在线支付</span>
                    <img src="./assets/yunjii/img/maibianjiao.png" class="icon">
                </div>
            </div>
        </div>
    </section>

    <section class="copyright">
        <p>Copyright © 2019-<?php echo date('Y') ?></p>
    </section>

    <footer class="footer">
        <div class="to_pay">
            <a id="payButton" href="javascript:void(0)">
                <span>立即支付￥请选择商品</span>
            </a>
        </div>
    </footer>
</div>



